#region Usings

using Castle.ActiveRecord;
using NUnit.Framework;
using Karma.Framework.Core.Repository.Configuration;

#endregion

namespace Karma.Framework.Core.UnitTest
{
    public abstract class AbstractRepositoryTestCase
    {
        protected SessionScope scope;

        [TestFixtureSetUp]
        public virtual void FixtureInit()
        {
            InitFramework();
        }

        [SetUp]
        public virtual void Init()
        {
            PrepareSchema();

            CreateScope();
        }

        [TearDown]
        public virtual void Terminate()
        {
            DisposeScope();

            DropSchema();
        }

        [TestFixtureTearDown]
        public virtual void TerminateAll()
        {
        }

        protected void FlushAndRecreateScope()
        {
            DisposeScope();
            CreateScope();
        }

        protected void CreateScope()
        {
            scope = new SessionScope();
        }

        protected void DisposeScope()
        {
            scope.Dispose();
        }

        protected virtual void PrepareSchema()
        {
            ActiveRecordStarter.CreateSchema();
        }

        protected virtual void DropSchema()
        {
            ActiveRecordStarter.DropSchema();
        }

        protected virtual void InitFramework()
        {
            ActiveRecordConfiguration.Initialize();
        }
    }
}